#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <assert.h>

using namespace std; 

#define D 2002

/*
4 5 1 2 3
4 2 4 3
2 3 3 3
2 5 2 4
*/

struct pnt_t {
	int line, col; 
}; 

struct pair_t {
	pnt_t a, b; 
}; 

struct cn_t {
	int coor; 
	int num; 
}; 

int m,n, k, l, d; //M,N,K,L,D
pair_t p[D]; 

cn_t cn[D]; 
int pn; 

int line[D]; 
int col[D]; 

bool cmp_num(cn_t &a, cn_t &b)
{
	if (a.num==b.num) {
		return a.coor < b.coor; 
	}
	return a.num > b.num; 
}

bool cmp_coor(cn_t &a, cn_t &b)
{
	return a.coor < b.coor; 
}


int main()
{
	int z; 
	//freopen("p1056_1.in", "r", stdin); 
	cin>>m>>n>>k>>l>>d; 
	for (int i=0; i<d; i++) {
		cin>>p[i].a.line>>p[i].a.col>>p[i].b.line>>p[i].b.col; 
		//cout<<p[i].a.line<<", "<<p[i].a.col<<", "<<p[i].b.line<<", "<<p[i].b.col<<"\n"; 
		if (p[i].a.line==p[i].b.line) {
			z = min(p[i].a.col, p[i].b.col); 
			col[z] ++; 
			//cout<<"col: "<<z<<"="<<col[z]<<"\n"; 
		} else if(p[i].a.col==p[i].b.col) {
			z = min(p[i].a.line, p[i].b.line); 
			line[z] ++; 
			//cout<<"line: "<<z<<"="<<line[z]<<"\n"; 
		} else {
			assert(0); 
		}
	}
	pn = 0; 
	for (int i=1; i<=m; i++) {
		if (line[i]==0) {
			continue; 
		}
		cn[pn].coor = i; 
		cn[pn].num = line[i]; 
		pn++; 
	}
	sort(cn, cn+pn, cmp_num); 
	z = min(pn, k); 
	sort(cn, cn+z, cmp_coor); 
	for (int i=0; i<z; i++) {
		cout<<cn[i].coor; 
		if (i!=z-1)
			cout<<" "; 
	}
	cout<<"\n"; 

	pn = 0; 
	for (int i=1; i<=n; i++) {
		if (col[i]==0) {
			continue; 
		}
		cn[pn].coor = i; 
		cn[pn].num = col[i]; 
		pn++; 
	}
	sort(cn, cn+pn, cmp_num); 
	z = min(pn, l); 
	sort(cn, cn+z, cmp_coor); 
	for (int i=0; i<z; i++) {
		cout<<cn[i].coor; 
		if (i!=z-1)
			cout<<" "; 
	}
	cout<<"\n"; 
	
	return 0; 
}


